﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Security;

namespace _03.ReadAFileOnTheComputer
{
    class Program
    {
        static void Main()
        {
            Console.Write("Enter the full path of the file you want to read: ");
            string filePath = Console.ReadLine();
            try
            {
                ReadFile(filePath);
                
                //DirectoryInfo dir = new DirectoryInfo(@"C:\Users\ivan-jquery\Desktop\Solution1");
                //DirectoryInfo[] subDirs = dir.GetDirectories();
                //foreach (DirectoryInfo subdirectory in subDirs)
                //{
                //    Console.WriteLine(subdirectory.Name);
                //}
            }
            catch (DirectoryNotFoundException)
            {
                Console.WriteLine("The file path contains a directory that cannot be found!");
            }
            catch (FileNotFoundException)
            {
                Console.WriteLine("The file '{0}' was not found!", filePath);
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("No file path is given!");
            }
            catch (ArgumentException)
            {
                Console.WriteLine("The entered file path is not correct!");
            }
            catch (PathTooLongException)
            {
                Console.WriteLine("The entered file path is too long - 248 characters are the maximum!");
            }
            catch (UnauthorizedAccessException uoae)
            {
                Console.WriteLine(uoae.Message);
            }
            catch (SecurityException)
            {
                Console.WriteLine("You don't have the required permission to access this file!");
            }
            catch (NotSupportedException)
            {
                Console.WriteLine("Invalid file path format!");
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.Message);
            }
        }

        static void ReadFile(string filePath)
        {
            string fileContent = File.ReadAllText(filePath);
            Console.WriteLine("The content of the file is: ");
            Console.WriteLine(fileContent);
        }
    }
}
